﻿Imports System.Data.Common
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.Common.Configuration
Imports FY.YinXinSDK
Imports FY.YinXinSDK.RecMsg
Imports FY.YinXinSDK.ReplyMsg
Imports Peer.PublicVBModule.VBReflection
Imports TjLog
Public Class ServiceProcess
    Private Shared lockobj As Object = New Object()

    Public Shared Function Process(Plat_Code As String, keyinfo As String, paras As String) As ReplyBaseMsg
        Dim result As ReplyBaseMsg
        Dim yixin_db As Database = EnterpriseLibraryContainer.Current.GetInstance(Of Database)("fyyixin")
        Try
            Dim CurLogicFlag As Integer = Convert.ToInt32(yixin_db.ExecuteScalar(CommandType.Text, "select stop_flag from t_servicelogic_info where plat_code='" & Plat_Code & "' and keyinfo='" & keyinfo & "'"))
            If Not ReflectStruct.ReflectHelperIns.GetReflectSetDic(Plat_Code).ContainsKey(keyinfo) Then
                If 1 = CurLogicFlag Then
                    result = New ReplyTextMsg() With {.Content = keyinfo & "当前业务逻辑已经被停止！"}
                    Return result
                End If
                If 0 = CurLogicFlag Then
                    ReflectStruct.ReadReflectDll(Plat_Code, keyinfo)
                Else
                    If 2 = CurLogicFlag Then
                        ReflectStruct.ReadReflectDll(Plat_Code, keyinfo)
                        yixin_db.ExecuteNonQuery(CommandType.Text, "update t_servicelogic_info set stop_flag=0 where plat_code='" & Plat_Code & "' and keyinfo='" & keyinfo & "'")
                    End If
            End If
				Else
                If 1 = CurLogicFlag Then
                    ReflectStruct.ClearOneReflectInfo(Plat_Code, keyinfo)
                    result = New ReplyTextMsg() With {.Content = keyinfo & "业务逻辑已经在内存中删除成功！"}
                    Return result
                End If
                If 2 = CurLogicFlag Then
                    ReflectStruct.ReadReflectDll(Plat_Code, keyinfo)
                    yixin_db.ExecuteNonQuery(CommandType.Text, "update t_servicelogic_info set stop_flag=0 where plat_code='" & Plat_Code & "' and keyinfo='" & keyinfo & "'")
                End If
				End If
            If ReflectStruct.ReflectHelperIns.GetReflectSetDic(Plat_Code).ContainsKey(keyinfo) Then
                Dim setNodeIns As ReflectSetNode = ReflectStruct.ReflectHelperIns.GetReflectSetDic(Plat_Code)(keyinfo)
                Dim obj As Object = ReflectStruct.ReflectHelperIns.ExcuteDll(setNodeIns.CurOrgCode, setNodeIns.CurDllPath, setNodeIns.CurNameSpace, setNodeIns.CurClassName, setNodeIns.CurMethodName, paras)
                Dim replyins As List(Of Object) = CType(obj, List(Of Object))
                Select Case Convert.ToInt32(replyins(0))
                    Case 0
                        result = CType(replyins(1), ReplyEmptyMsg)
                        Return result
                    Case 1
                        result = CType(replyins(1), ReplyTextMsg)
                        Return result
                    Case 2
                        result = CType(replyins(1), ReplyNewsMsg)
                        Return result
                    Case 4
                        result = CType(replyins(1), ReplyMusicMsg)
                        Return result
                    Case Else
                        result = ReplyEmptyMsg.Instance
                        Return result
                End Select
            End If
        Catch ex As Exception
            Dim ErrorStr As String = TjLog.Log.getLogInfo(New StackFrame(True))
            TjLog.Log.ErrorLog("执行平台" + Plat_Code + "的服务" + keyinfo + "异常：" + ex.ToString() + ErrorStr, Plat_Code, "01", "执行已经导入内存的业务逻辑", "ExcuteDll")
            TjLog.Log.FileLog.Error("执行平台" + Plat_Code + "的服务" + keyinfo + "异常：" + ex.ToString() + ErrorStr)
        End Try
        result = ReplyEmptyMsg.Instance
        Return result
    End Function
End Class
